/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import fever.medias.video.VideoCuePointType;
import fever.utils.Stringifier;
import fever.utils.StringUtil;

/**
 * {@code VideoCuePoint } class.
 *
 * @author Romain Ecarnot
 */
class fever.medias.video.VideoCuePoint
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
		
	private var _name : String;
	private var _type : VideoCuePointType;
	private var _time : Number;
	private var _parameters : Object;
	
	
	//-------------------------------------------------------------------------
	// Public Properties
	//-------------------------------------------------------------------------
		
	/**
	 * The name given to the cue point when it was embedded in the FLV file.
	 */
	public function get name() : String { return _name; }
	
	/**
	 * The time in seconds at which the cue point occurred in the video 
	 * file during playback.
	 */
	public function get time() : Number { return _time; }
	
	/**
	 * The type of cue point that was reached, can be : 
	 * <ul>
	 *   <li>{@link fever.medias.video.VideoCuePointType#EVENT}</li> 
	 *   <li>{@link fever.medias.video.VideoCuePointType#NAVIGATION}</li>
	 * </ul>
	 */
	public function get type() : VideoCuePointType { return _type; }
	
	/** 
	 * A associative array of name/value pair strings specified for this cue point. 
	 */
	public function get parameters() : Object { return _parameters; }
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Creates {@link VideoCuePoint} from basic object structure.
	 * 
	 * <p>Usually {@code o} is retreive during medadata data loop.
	 */
	public static function create( o : Object ) : VideoCuePoint
	{
		return new VideoCuePoint( o.name, o.time, o.type, o.parameters );	
	}
	
	/**
	 * Constructor.
	 */
	public function VideoCuePoint( label : String, stamp : Number, cueType : VideoCuePointType, parameters : Object )
	{
		_name = StringUtil.replace( label, "\\n", "\n" );
		_time = stamp;
		_type = ( cueType != undefined ) ? cueType : VideoCuePointType.CUSTOM;
		
		_parameters = parameters;
	}
	
	/**
	 * Returns string representation.
	 */
	public function toString() : String
	{
		return Stringifier.parse( this, _name + " ( " + _time + " ) " );
	}
}